package com.xbongbong.paas.service;

import com.alibaba.fastjson.JSONArray;
import com.xbongbong.paas.domain.entity.ext.PaasFormDataEntityExt;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.field.RelyPoJo;
import com.xbongbong.paas.pojo.dto.ExplainCompareListDTO;
import com.xbongbong.paas.pojo.dto.ExplainRelationListDTO;
import com.xbongbong.paas.pojo.dto.ExplainRelyAttrListDTO;
import com.xbongbong.paas.pojo.dto.ExplainRelyBusinessAttrListDTO;
import com.xbongbong.paas.pojo.dto.ExplainScreenListDTO;
import com.xbongbong.paas.pojo.dto.FormExplainAddDTO;
import com.xbongbong.paas.pojo.dto.FormExplainListDTO;
import com.xbongbong.paas.pojo.dto.LinkCompareFieldDTO;
import com.xbongbong.paas.pojo.dto.LinkDisplayFieldDTO;
import com.xbongbong.paas.pojo.dto.LinkExplainListDTO;
import com.xbongbong.paas.pojo.dto.PartFormExplainListDTO;
import com.xbongbong.paas.pojo.dto.ProductDataRelyDTO;
import com.xbongbong.paas.pojo.vo.ExplainCompareListVO;
import com.xbongbong.paas.pojo.vo.ExplainRelationListVO;
import com.xbongbong.paas.pojo.vo.ExplainRelyAttrListVO;
import com.xbongbong.paas.pojo.vo.ExplainRelyBusinessAttrListVO;
import com.xbongbong.paas.pojo.vo.ExplainScreenListVO;
import com.xbongbong.paas.pojo.vo.FormExplainAddVO;
import com.xbongbong.paas.pojo.vo.FormExplainListVO;
import com.xbongbong.paas.pojo.vo.LinkCompareFieldVO;
import com.xbongbong.paas.pojo.vo.LinkDisplayFieldVO;
import com.xbongbong.paas.pojo.vo.LinkExplainListVO;
import com.xbongbong.paas.pojo.vo.PartFormExplainListVO;
import com.xbongbong.paas.pojo.vo.ProductDataRelyVO;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.pro.formexplain.pojo.dto.DynamicManagerDTO;
import com.xbongbong.pro.formexplain.pojo.dto.ExplainFilterConditionDTO;
import com.xbongbong.pro.formexplain.pojo.dto.ExplainMapLinkDataDTO;
import com.xbongbong.pro.formexplain.pojo.dto.ExplainOperatorDTO;
import com.xbongbong.pro.formexplain.pojo.dto.FormExplainAddBatchDTO;
import com.xbongbong.pro.formexplain.pojo.dto.FormExplainDeleteDTO;
import com.xbongbong.pro.formexplain.pojo.dto.LinkFormItemDTO;
import com.xbongbong.pro.formexplain.pojo.dto.LinkKeyExplainListDTO;
import com.xbongbong.pro.formexplain.pojo.vo.DynamicManagerVO;
import com.xbongbong.pro.formexplain.pojo.vo.ExplainFilterConditionVO;
import com.xbongbong.pro.formexplain.pojo.vo.ExplainMapLinkDataVO;
import com.xbongbong.pro.formexplain.pojo.vo.ExplainOperatorVO;
import com.xbongbong.pro.formexplain.pojo.vo.FormExplainAddBatchVO;
import com.xbongbong.pro.formexplain.pojo.vo.FormExplainDeleteVO;
import com.xbongbong.pro.formexplain.pojo.vo.LinkFormItemVO;
import com.xbongbong.pro.formexplain.pojo.vo.LinkKeyExplainListVO;
import com.xbongbong.pro.formexplain.pojo.vo.RuleFormExplainListVO;
import com.xbongbong.pro.paymentsheet.pojo.dto.AccountListDTO;
import com.xbongbong.pro.paymentsheet.pojo.vo.AccountListVO;
import com.xbongbong.saas.enums.XbbRefTypeEnum;

import java.util.List;
import java.util.Map;

/**
 * @author: wufeng
 * @date: 2018/9/10 10:08
 * @desrcption: 字段描述
 */
public interface PaasFormExplainService {

    /**
     * 初始化字段信息
     * @author 吴峰
     * @date 2019/1/22 14:01
     * @param formExplainAddDTO
     * @return com.xbongbong.paas.pojo.vo.FormExplainAddVO
     * @throws XbbException
     */
    FormExplainAddVO add(FormExplainAddDTO formExplainAddDTO) throws XbbException;

    /**
     * 批量插入初始化信息
     * @param formExplainAddBatchDTO
     * @return 返回插入成功的信息
     * @throws XbbException
     */
    FormExplainAddBatchVO addBatch(FormExplainAddBatchDTO formExplainAddBatchDTO) throws XbbException;
    /**
     * 关联数据或者关联查询的关联表的关联字段
     * @param formExplainListDTO
     * @return 关联数据或者关联查询的关联表的关联
     * @throws XbbException
     */
    FormExplainListVO linkList(FormExplainListDTO formExplainListDTO) throws XbbException;


    /**
     * 获取某个应用的某个表单的所有字段--需要对比的列表，部分字段不需要，需要过滤，主要检索ExplainRelation的数据
     * @param explainCompareListDTO
     * @return
     * @throws XbbException
     */
    ExplainCompareListVO compareList(ExplainCompareListDTO explainCompareListDTO) throws XbbException;

    /**
     * 字段筛选列表
     * @param explainScreenListDTO
     * @return
     * @throws XbbException
     */
    ExplainScreenListVO screenList(ExplainScreenListDTO explainScreenListDTO) throws XbbException;

    /**
     * 根据字段类型，返回匹配的字段
     * @param explainCompareListDTO
     * @return
     * @throws XbbException
     */
    ExplainRelationListVO relationList(ExplainRelationListDTO explainCompareListDTO) throws XbbException;
    /**
     * 关联表单可选择字段
     * @param explainRelyAttrListDTO
     * @return
     * @author xingxing.xiao
     * @date 2020/07/31 16:43
     */
    ExplainRelyAttrListVO relyAttrList(ExplainRelyAttrListDTO explainRelyAttrListDTO) throws XbbException;

    /**
     * 关联表单可选择字段 - 多模板
     * @param relyBusinessAttrListDTO
     * @return
     * @author xingxing.xiao
     * @date 2020/07/31 16:43
     */
    ExplainRelyBusinessAttrListVO relyBusinessAttrList(ExplainRelyBusinessAttrListDTO relyBusinessAttrListDTO) throws XbbException;

    /**
     * 条件字段联动查询
     * @param explainRelationListDTO
     * @author xingxing.xiao
     * @date 2020/07/29 15:14
     */
    ExplainRelationListVO relationAttrList(ExplainRelationListDTO explainRelationListDTO) throws XbbException;

    /**
     * 表单规则字段列表-业务规则专用
     * @param formExplainListDTO
     * @return
     * @throws XbbException
     */
    RuleFormExplainListVO ruleList(FormExplainListDTO formExplainListDTO) throws XbbException;
    /**
     * 表单条件字段联动查询-业务规则专用
     * @author 吴峰
     * @date 2019/5/5 9:45
     * @param explainRelationListDTO
     * @return com.xbongbong.paas.pojo.vo.ExplainRelationListVO
     * @throws XbbException 业务异常
     */
    ExplainRelationListVO relationRuleList(ExplainRelationListDTO explainRelationListDTO) throws XbbException;

    /**
     * 获取操作对应的字段-业务规则专用
     * @param explainOperatorDTO
     * @return
     * @throws XbbException
     */
    ExplainOperatorVO operatorRuleList(ExplainOperatorDTO explainOperatorDTO) throws XbbException;

    /**
     * 获取部分字段信息，过滤掉 LinkConditionNeedFilterFieldEnum 中的字段
     * @param formExplainListDTO
     * @return
     * @throws XbbException
     */
    PartFormExplainListVO partExplainList(PartFormExplainListDTO formExplainListDTO) throws XbbException;

    /**
     * 获取某个应用的某个表单的所有字段
     * @param linkExplainListDTO
     * @return 返回字段
     * @throws XbbException
     */
    LinkExplainListVO list(LinkExplainListDTO linkExplainListDTO) throws XbbException;

    /**
     * 获取默认值-数据联动-联动表单的比较字段
     * @param linkCompareFieldDTO
     * @return
     * @throws XbbException
     */
    LinkCompareFieldVO linkCompareList(LinkCompareFieldDTO linkCompareFieldDTO) throws XbbException;

    /**
     * 获取默认值-数据联动-联动表单的显示字段
     * @param linkDisplayFieldDTO
     * @return
     * @throws XbbException
     */
    LinkDisplayFieldVO linkDisplayFieldList(LinkDisplayFieldDTO linkDisplayFieldDTO) throws XbbException;

    LinkDisplayFieldVO linkConvertFieldList(LinkDisplayFieldDTO linkDisplayFieldDTO) throws XbbException;

    /**
     * 获取关联新建的解释和数据
     *
     * @param linkFormItemDTO 关联新建入参
     * @author feng.zheng
     * @return com.xbongbong.pro.formexplain.pojo.vo.LinkFormItemVO
     * @throws XbbException 业务异常
     * @date 2019/2/20 19:29
     */
    LinkFormItemVO linkFormList(LinkFormItemDTO linkFormItemDTO) throws XbbException;

    /**
     * 根据attr属性判断某个具体字段是否必填
     *
     * @param explainList 字段解释集合
     * @param attr 属性attr
     * @author lcx
     * @since V1.0
     * @return 是否必填，true：是；false：否
     * @date 2019/2/19 10:07
     */
    Boolean checkRequiredByAttr(List<FieldAttrEntity> explainList, String attr) throws XbbException;

    /**
     * 根据saasAttr属性判断某个具体字段是否必填
     *
     * @param explainList 字段解释集合
     * @param saasAttr saasAttr属性
     * @author lcx
     * @since V1.0
     * @return 是否必填，true：是；false：否
     * @date 2019/2/19 10:07
     */
    Boolean checkRequiredBySaasAttr(List<FieldAttrEntity> explainList, String saasAttr) throws XbbException;

    /**
     * 根据attr属性判断某个具体字段是否启用
     *
     * @param explainList 字段解释集合
     * @param attr saasAttr属性
     * @author lcx
     * @since V1.0
     * @return 是否可见，true：是；false：否
     * @date 2019/2/19 10:07
     */
    Boolean checkVisibleByAttr(List<FieldAttrEntity> explainList, String attr) throws XbbException;

    /**
     * 判断产品成本字段是否启用
     *
     * @param corpid 公司id
     * @author lcx
     * @since V1.0
     * @return 是否必填，true：是；false：否
     * @date 2019/2/19 10:07
     */
    Boolean checkProductCostVisibleByAttr(String corpid) throws XbbException;

    /**
     * 根据业务类型，获取字段解释，返回Map
     *
     * @param businessType 业务类型
     * @param corpid 公司id
     * @author chaoxiong.lei
     * @date 19:31 2019/3/22
     * @since v1.0
     * @return key为attr，value为字段解释实体
     **/
    Map<String, FieldAttrEntity> getFieldAttrMapByBusinessType(Integer businessType, String corpid) throws XbbException;

    /**
     * 列表新建编辑保存详情，部分字段处理
     * 例如客户合同状态
     * @param explainList
     * @param businessType
     * @param corpid
     * @return
     */
    Map<String,FieldAttrEntity> getExpalinMap(List<FieldAttrEntity> explainList, Integer businessType, String corpid,Long formId) throws XbbException;

    /**
     * 列表新建编辑保存详情，部分字段处理
     * 例如客户合同状态
     * @param explainList
     * @param businessType
     * @param corpid
     * @param formId
     * @return
     */
    List<FieldAttrEntity> handleExplainList(List<FieldAttrEntity> explainList, Integer businessType, String corpid, Long formId) throws XbbException;

    /**
     * 删除字段解释
     * @param formExplainDeleteDTO
     * @return
     * @throws XbbException
     */
    FormExplainDeleteVO delete(FormExplainDeleteDTO formExplainDeleteDTO) throws XbbException;

    /**
     * 获取关联主键字段
     * @param linkKeyExplainListDTO
     * @return
     * @throws XbbException
     */
    LinkKeyExplainListVO linkKeyList(LinkKeyExplainListDTO linkKeyExplainListDTO) throws XbbException;

    List<PaasFormDataEntityExt> checkDataHavaEditAndDelPermission(List<PaasFormDataEntityExt> formDataList, Integer linkBusinessType, LinkFormItemDTO linkFormItemDTO, boolean isProcess) throws XbbException;

    /**
     *  获取流程动态审批人
     *
     * @param dynamicManagerDTO
     * @throws
     * @return
     * @author hongxiao
     * @date 2019-11-06 09:49
     * @since
     * @version
     */
    DynamicManagerVO dynamicManager(DynamicManagerDTO dynamicManagerDTO) throws XbbException;

    /**
     *
     * @param explainMapLinkDataDTO
     * @return
     * @throws XbbException
     */
    ExplainMapLinkDataVO explainMapByLinkData(ExplainMapLinkDataDTO explainMapLinkDataDTO) throws XbbException;

    /**
     * 获取关联产品联动表单设置
     *
     * @param productDataRelyDTO 参数
     * @return 默认联动设置
     * @throws XbbException 异常
     */
    ProductDataRelyVO productDataRely(ProductDataRelyDTO productDataRelyDTO) throws XbbException;

    /**
     * 新建时关联产品联动默认设置
     * @param corpid 公司
     * @param formId 表单id
     * @return 关联关系
     */
    List<RelyPoJo> selectProductRely(String corpid, Long formId);

    /**
     * 获取付款单/回款单的回款账户/付款账户列表
     * @param accountListDTO
     * @return
     * @throws XbbException
     */
    AccountListVO getAccountList(AccountListDTO accountListDTO) throws XbbException;

    /**
     * 处理合同或者采购合同下需要移除的回款单、回款计划或者付款单、付款计划
     *
     * @param corpid
     * @param xbbRefTypeEnum
     * @param linkXbbRefTypeEnum
     * @param linkArray
     * @throws XbbException
     */
    void handProcessShouldRemoveValue(String corpid, XbbRefTypeEnum xbbRefTypeEnum, XbbRefTypeEnum linkXbbRefTypeEnum, JSONArray linkArray) throws XbbException;

    /**
     * 获取当前表单可以作为过滤条件的字段列表
     * @param explainFilterConditionDTO
     * @return
     * @throws XbbException
     */
    ExplainFilterConditionVO ruleFilterConditionList(ExplainFilterConditionDTO explainFilterConditionDTO) throws XbbException;

    LinkFormItemVO workflowLinkFormList(LinkFormItemDTO linkFormItemDTO) throws XbbException;

    /**
     * 获取开放的可选范围开放的作为过滤条件的字段列表
     * @param explainFilterConditionDTO
     * @return
     * @throws XbbException
     */
    ExplainFilterConditionVO optionalRangeConditionList(ExplainFilterConditionDTO explainFilterConditionDTO) throws XbbException;
}
